<?php

namespace EShop\Controller;

/**
 * PasspoartController 类
 *
 * @since VER:1.0; DATE:2016-8-17; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added.
 */
class PassportController extends \Think\Controller {

    public function login() {
        $this->display();
    }

    function login_save($uname = '', $password = '') {
        if (strlen($uname) > 16 || strlen($password) > 32) {
            exit('参数无效!');
        }
        $m_login = new \XWAM\Model\LoginModel();
        $result = $m_login->login(I('uname'), I('password'), null, $msg);
        if ($result) {
            session('login', $msg);
            redirect(U('EShop/Home/index'));
        } else {
            $this->error($msg);
        }
    }

    public function logout() {
        $m_login = new \XWAM\Model\LoginModel();
        $m_login->logout();
        $this->success('账户登出成功!', U('EShop/Index/index'));
    }

    public function signup() {
        $this->display();
    }

    function signup_save() {
        $data = array(
            'user_name' => I('login_name'),
            'password' => I('login_password'),
            'repassword' => I('psw_confirm'),
        );
        $m_user = new \XWAM\Model\UserModel();
        $result = $m_user->signup($data);
        if ($result['status']) {
            $this->success('注册成功!', U('EShop/Passport/login'));
        } else {
            $this->error($result['info']);
        }
    }

    function forget_password() {
        $this->display();
    }

    function forget_password_save() {
        $m_user = new XWAM\Model\UserModel();
        $m_user->update_password();
    }

    function get_user_zone() {
        $user_login_data = array();
        if (user_check_login($user_login_data)) {
            echo '<span>欢迎您，<a href="', U('MyHome/index'), '">', $user_login_data['user_name'], '</a> <a href="', U('MyHome/index'), '">会员中心</a> | <a href="', U('Passport/logout'), '">退出</a></span>';
        } else {
            echo '<span>欢迎您，<a href="', U('Passport/login'), '">登录</a> | <a href="', U('Passport/signup'), '">注册</a></span>';
        }
    }

}
